package com.tianzeculture.stagebao.activity.artist.fragment;

import android.content.Intent;
import android.text.TextUtils;
import android.view.View;
import android.widget.AdapterView;
import android.widget.EditText;
import android.widget.Spinner;
import android.widget.TextView;

import com.tianzeculture.stagebao.R;
import com.tianzeculture.stagebao.activity.artist.MyArtistActivity;
import com.tianzeculture.stagebao.base.BaseActivity;
import com.tianzeculture.stagebao.bean.PersonnelPoolBean;
import com.tianzeculture.stagebao.net.ArtistRestUsage;
import com.tianzeculture.stagebao.network.Request;
import com.tianzeculture.stagebao.network.enity.MSG;
import com.tianzeculture.stagebao.network.util.ToastUtil;
import com.tianzeculture.stagebao.util.StatusBarUtil;

import org.greenrobot.eventbus.EventBus;

import java.util.HashMap;
import java.util.Map;

import butterknife.BindView;
import butterknife.OnClick;

/**
 * Created by Administrator on 2018/7/4 0004.
 * 加入人才库-我的报价
 */

public class ArtistAddPriceActivity extends BaseActivity {
    @BindView(R.id.tvTitle)
    TextView tvTitle;
    @BindView(R.id.tvRight)
    TextView tvRight;
    @BindView(R.id.etMin)
    EditText etMin;

    @BindView(R.id.spinner)
    Spinner spinner;
    //    @BindView(R.id.lvPrice)
//    RecyclerView listView;
//    @Request
//    CommonRestUsage commonRestUsage = null;
//    private int getOfferList = 111;
    private static final int OFFER_CODE = 5;

    String[] strings = {"歌手", "模特", "主持", "网红"};
    String offer = "歌手";
    boolean isEdit;

    private int addOfferId = 8;
    @Request
    ArtistRestUsage artistRestUsage = null;

    @Override
    public void initUI() {
        super.initUI();
        StatusBarUtil.setWindowStatusBarColor(this, R.color.colorGray_F8);
        tvTitle.setText(getString(R.string.my_price));
        tvRight.setText(getString(R.string.add_price));
        tvRight.setVisibility(View.VISIBLE);
        isEdit = getIntent().getBooleanExtra("isEdit", false);
//        offer = getIntent().getStringExtra("job");
////        String[] arr = offer.split("\\|");
//        spinner.setText(offer);
        //创建布局管理
//        LinearLayoutManager layoutManager = new LinearLayoutManager(this);
//        layoutManager.setOrientation(LinearLayoutManager.VERTICAL);
//        listView.setLayoutManager(layoutManager);
//        listView.addItemDecoration(new DividerItemDecoration(this, DividerItemDecoration.VERTICAL));
//        commonRestUsage.getOfferList(getOfferList);
        spinner.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
                offer = strings[i];
            }
        });
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
//        if (requestCode == OFFER_CODE) {
//            commonRestUsage.getOfferList(getOfferList);
//        }
    }

    @OnClick(R.id.tvRight)
    public void addPrice(View view) {
//        startActivityForResult(new Intent(ArtistEditPriceActivity.this, ArtistEditPriceDetailActivity.class), OFFER_CODE);
        if (TextUtils.isEmpty(etMin.getText())) {
            ToastUtil.showShort(this, "请输入价格");
            return;
        }
        Map<String, String> map = new HashMap<>();
        map.put("name",offer );
        map.put("price", etMin.getText().toString().trim());
        artistRestUsage.offerAdd(addOfferId, map);
//        offer = offer + "-" + etMin.getText().toString().trim() + "/每小时";
//        Intent intent = new Intent();
//        intent.putExtra("atistPrice", offer);
//        setResult(RESULT_OK, intent);
//        finish();
    }

    @Override
    public void refreshUI(int taskId, MSG msg) {
        super.refreshUI(taskId, msg);
//        if (taskId == getOfferList) {
//            ToastUtil.show(this, msg.getMessage());
//            if (msg.getData()) {
//                ResultBean resultBean = (ResultBean) msg.getObj();
//                final List<OfferBean> list = resultBean.getOfferList();
//                //创建适配器
//                ArtistPriceAdapter adapter = new ArtistPriceAdapter(R.layout.item_artist_price, list);
//                adapter.setOnItemClickListener(new BaseQuickAdapter.OnItemClickListener() {
//                    @Override
//                    public void onItemClick(BaseQuickAdapter adapter, View view, int position) {
//                        OfferBean offerBean = list.get(position);
//                        String str = offerBean.getWorkType() + "-" + offerBean.getDetailWork() + "-" + offerBean.getOfferMoney() + "/" + offerBean.getOffer();
//                        Intent intent = new Intent();
//                        intent.putExtra("atistPrice", str);
//                        setResult(RESULT_OK, intent);
//                        finish();
//                    }
//                });
//                //给RecyclerView设置适配器
////                listView.setAdapter(adapter);
//
//            }


        if (taskId == addOfferId) {
            Intent intent = new Intent();
            intent.putExtra("atistPrice", offer + "-" + etMin.getText().toString().trim() + "/每小时");
            setResult(RESULT_OK, intent);
            finish();
        }
    }

    @Override
    protected int getLayoutResID() {
        return R.layout.activity_add_price;
    }
}
